package com.qing.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

import com.qing.service.NoticeService;
import com.qing.pojo.Notice;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author qinghua
 * @since 2022-06-06
 */
@RestController
@RequestMapping("/notice")
public class NoticeController {
    @Autowired
    private NoticeService noticeService;

    @PostMapping("/insert")
    public Boolean save(@RequestBody Notice notice) {
        return noticeService.saveOrUpdate(notice);
    }

    @GetMapping("/deleteById/{id}")
    public Boolean delete(@PathVariable Integer id) {
        return noticeService.removeById(id);
    }

    @GetMapping("/queryAll")
    public List<Notice> queryAll() {
        return noticeService.list(new QueryWrapper<Notice>().orderByDesc("create_time"));
    }

    @GetMapping("/queryById/{id}")
    public Notice findOne(@PathVariable Integer id) {
        return noticeService.getById(id);
    }

    @GetMapping("/queryAllAndName")
    public List<Map<String,Object>> queryAllAndName(){
        return noticeService.queryAllAndName();
    }

    @PostMapping("/queryNoticeByTitle")
    public List<Map<String, Object>> queryNoticeByTitle(@RequestBody String str) {
        String title = JSONObject.parseObject(str).getString("title");
        return noticeService.queryNoticeByTitle(title);
    }

}

